$(function(){

	/*========== Allcategory Onmouserover Background ==========*/
	$('ul.category li').mouseover(function(){
		$(this).addClass('mouseover');
	});
	$('ul.category li').mouseout(function(){
		$(this).removeClass('mouseover');
	});

	/*========== Indexpage all category show=========*/
	if($('.webpostion').attr('is') == 'index'){
		$('.category_box').css('display','block');
	}else{
		/*========== Allcategory Show Event==========*/
		var indexCategory = $('.category_box');
		$('.allcate').hover(function () {
		    indexCategory.show();
		  },function () {
		    var t = setTimeout(function () {
				indexCategory.hide();
			}, 500);
			indexCategory.mouseenter(function () {
				clearTimeout(t);
			}).mouseleave(function () {
				$(this).hide();
			});
		});
	}

	/*========== Goodscart Show ==========*/
	buyCartShow();
	$('.buycart_c').mouseover(function(){
		$('.buycart_c .cartgs_show').css('display','block');
	});
	$('.buycart_c').mouseout(function(){
		$('.buycart_c .cartgs_show').css('display','none');
	});

 	/*======== ajax delete buycart's goods =======*/
    $('p.delcartgs').live('click',function(){
        var that = $(this).parent();
        $.post(DelGsPath,{'clid':$(this).parent().attr('cartlid')},function(data){
            eval('var data = data');
            if(data.status == 'ok'){
                //updata buycart's data
                $('span.gsnum').text(data.cartGsNumT);
                $('font.tcartgsnum').text(data.cartGsNumT);
                buyCartShow();
                that.remove();
            }else if(data.status == 'er'){
                alert("请刷新页面再试！");
            }
        },'json');
    });

    //回到顶部
    $("#backtop").click(function(){
    	$(document).scrollTop(0);
    });
    $(window).scroll(function(){
    	// alert($(document).scrollTop())
    	// alert($(window).height())
    	if($(document).scrollTop() > $(window).height()){
    		$("#backtop").css('display','block');
    	}else{
    		$("#backtop").css('display','none');
    	}
    });
});

function buyCartShow(){
	if($('span.gsnum').text() != '0'){
		$('div.empty').css('display','none');
		$('div.tocart').css('display','block');
		$('ul.cartgslist_c').css('display','block');
		$('ul.cartgslist_c li').hover(function(){
			$(this).css('background','#FFF7E5');
		},
		function(){
			$(this).css('background','#FFFFFF');
		});
	}else if($('span.gsnum').text() == '0'){
		$('div.empty').css('display','block');
		$('div.tocart').css('display','none');
		$('ul.cartgslist_c').css('display','none');
	}
}